package com.webamc.dao.db4o;

import com.webamc.dao.IUserDao;
import com.webamc.model.User;
import com.webamc.util.DB4OUtil;
import org.apache.log4j.Logger;

import java.util.List;

/**
 * Date: Mar 9, 2009
 * Time: 12:16:45 AM
 */
public class UserDao implements IUserDao {
    private Logger log = Logger.getLogger(UserDao.class);

    public boolean create(User c) {
        log.info("Inside usercreate - " + c.getUsername());
        return DB4OUtil.insert(c);
    }

    public boolean update(User c) {
        log.info("Inside user update - " + c.getUsername());
        return DB4OUtil.update(c);
    }

    public User view(int id) {
        User proto = new User();
        proto.setUserId(id);
        List<User> l = search(proto);
        return l.size() > 0 ? l.get(0) : null;
    }

    public List<User> search(User dummy) {
        return DB4OUtil.select(dummy);
    }

    public List<User> browse() {
        return DB4OUtil.getAll(User.class);
    }
}
